package com.agu.mgt.fms.service;

import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.agu.entity.address.EntAddressEntity;
import com.agu.entity.fms.FsmsSendEntity;
import com.agu.entity.fsmsmgt.FsmsTemplateCanvasEntity;
import com.agu.entity.fsmsmgt.FsmsTemplateEntity;
import com.agu.mgt.fms.dao.FsmsSendDao;
import com.agu.utils.Query;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;


@Service("fsmsSendService")
@Transactional(readOnly = true)
public class FsmsSendService{
	@Autowired
	private FsmsSendDao fsmsSendDao;
	
	
	public FsmsSendEntity queryObject(String sendId){
		return fsmsSendDao.queryObject(sendId);
	}
	
	
	public List<FsmsSendEntity> queryList(Map<String, Object> map){
		return fsmsSendDao.queryList(map);
	}

	
	public List<FsmsSendEntity> queryTemplateList(Map<String, Object> map){
		return fsmsSendDao.queryTemplateList(map);
	}
	
	public List<EntAddressEntity> queryAddressList(Map<String, Object> map){
		return fsmsSendDao.queryAddressList(map);
	}
	
	
	public FsmsTemplateEntity queryTemplateInfo(Integer templateId){
		
		FsmsTemplateEntity template =	fsmsSendDao.queryTemplateInfo(templateId);
		List<FsmsTemplateCanvasEntity> list = fsmsSendDao.queryCanvasList(templateId);
		template.setCavnenList(list);
		
		return template;
	}

	
	public Page<FsmsSendEntity> queryPageList(Query query){
	    PageHelper.startPage(query.getPage(), query.getLimit());
	    return fsmsSendDao.queryPageList(query);
	}
	
	
	public int queryTotal(Map<String, Object> map){
		return fsmsSendDao.queryTotal(map);
	}
	
	
	@Transactional
	public void save(FsmsSendEntity fsmsSend){
		String sendId = UUID.randomUUID().toString();
		
		fsmsSend.setSendId(sendId);
		
		
		
		
		
		fsmsSendDao.save(fsmsSend);
	}
	
	
	@Transactional
	public void update(FsmsSendEntity fsmsSend){
		fsmsSendDao.update(fsmsSend);
	}
	
	
	@Transactional
	public void delete(String sendId){
		fsmsSendDao.delete(sendId);
	}
	
	
	@Transactional
	public void deleteBatch(String[] sendIds){
		fsmsSendDao.deleteBatch(sendIds);
	}
}
